<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>专业化评价预警工具 - 注册</title>
    <style>
        /* 保留原有的样式 */
        .container {
            background-color: white;
            padding: 2rem;
            border-radius: 8px;
            box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 400px;
            position: relative;
            overflow: hidden;
        }
        .container::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background-color: #2a9d8f;
        }
        .container::after {
            content: '';
            position: absolute;
            top: -50px;
            right: -50px;
            width: 100px;
            height: 100px;
            background-color: rgba(42, 157, 143, 0.1);
            border-radius: 50%;
        }
        h1 {
            color: #333;
            margin-bottom: 1.5rem;
            font-size: 1.75rem;
            text-align: center;
        }
        .input-group {
            margin-bottom: 1.25rem;
            position: relative;
        }
        label {
            display: block;
            margin-bottom: 0.5rem;
            color: #555;
            font-size: 0.9rem;
        }
        input[type="text"],
        input[type="password"],
        input[type="email"] {
            width: 100%;
            padding: 0.75rem;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 1rem;
            transition: border-color 0.3s, box-shadow 0.3s;
        }
        input[type="text"]:focus,
        input[type="password"]:focus,
        input[type="email"]:focus {
            outline: none;
            border-color: #2a9d8f;
            box-shadow: 0 0 0 3px rgba(42, 157, 143, 0.2);
        }
        .form-switch {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1.5rem;
            font-size: 0.9rem;
        }
        .form-switch a {
            color: #2a9d8f;
            text-decoration: none;
            transition: color 0.3s;
        }
        .form-switch a:hover {
            color: #238b7e;
            text-decoration: underline;
        }
        .submit-button {
            width: 100%;
            padding: 0.75rem;
            background-color: #2a9d8f;
            color: white;
            border: none;
            border-radius: 4px;
            font-size: 1rem;
            cursor: pointer;
            transition: background-color 0.3s, transform 0.1s;
        }
        .submit-button:hover {
            background-color: #238b7e;
        }
        .submit-button:active {
            transform: translateY(1px);
        }
        .system-info {
            margin-top: 2rem;
            padding-top: 1rem;
            border-top: 1px solid #eee;
            text-align: center;
            color: #777;
            font-size: 0.875rem;
        }
        @media (max-width: 480px) {
            .container {
                padding: 1.5rem;
            }
            h1 {
                font-size: 1.5rem;
            }
        }
        .hidden {
            display: none;
        }
        .delete-button {
            background-color: #e63946;
        }
        .delete-button:hover {
            background-color: #d62828;
        }
    </style>
</head>
<body>
<div id="register_div" style="position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);width: 400px;display: none">
    <div class="container">

        <div id="registerForm">
            <h1>专业化评价预警工具 - 注册</h1>
            <form @submit.prevent="submit">
                <div class="input-group">
                    <label for="registerUsername">用户名</label>
                    <input type="text" id="registerUsername" name="username" placeholder="请输入用户名" required>
                </div>
                <div class="input-group">
                    <label for="registerPassword">密码</label>
                    <input type="password" id="registerPassword" name="password" placeholder="请输入密码" required>
                </div>
                <div class="input-group">
                    <label for="confirmPassword">确认密码</label>
                    <input type="password" id="confirmPassword" name="confirm-password" placeholder="请再次输入密码" required>
                </div>
                <div class="input-group">
                    <label>账号权限等级</label>
                    <div class="checkbox-group" style="width: 100%;">
                        <label><input type="checkbox" name="permissionLevel" value="1"> 劳动组织预警管理</label>
                        <label><input type="checkbox" name="permissionLevel" value="2"> 员工预警管理</label>
                        <label><input type="checkbox" name="permissionLevel" value="3"> 人才开发预警管理</label>
                        <label><input type="checkbox" name="permissionLevel" value="4"> 干部预警管理</label>
                    </div>
                </div>
<!--                <div class="admin-credentials">-->
<!--                    <div class="input-group">-->
<!--                        <label for="adminUsername">管理员账号</label>-->
<!--                        <input type="text" id="adminUsername" name="adminUsername" placeholder="请输入管理员账号" required>-->
<!--                    </div>-->
<!--                </div>-->
<!--                <div class="input-group">-->
<!--                    <label for="adminPassword">管理员密码</label>-->
<!--                    <input type="password" id="adminPassword" name="adminPassword" placeholder="请输入管理员密码" required>-->
<!--                </div>-->
                <div class="form-switch">
                    <a href="#" onclick="showLoginForm()">返回首页</a>
                </div>
                <button type="submit" class="submit-button">注册</button>
            </form>
        </div>
        <div class="system-info">
            专业化评价预警工具
        </div>
    </div>
</div>
<script src="${ROOT}/mind/js/vue2.js"></script>
<link href="${ROOT}/mind/css/element-ui.css" rel="stylesheet">
<!-- 引入Element Plus的JavaScript -->
<script src="${ROOT}/mind/js/element-ui.js"></script>
<script>
    new Vue({
        el: '#register_div',
        methods:{
            showLoginForm(){
                document.getElementById('loginDiv').style.display = 'none'
            },
            submit(){
                const username = document.getElementById('registerUsername').value;
                const password = document.getElementById('registerPassword').value;
                const confirmPassword = document.getElementById('confirmPassword').value;
                // const adminUsername = document.getElementById('adminUsername').value;
                // const adminPassword = document.getElementById('adminPassword').value;
                const result = Array.from(document.querySelectorAll('input[name="permissionLevel"]:checked')).map(el => el.value);
                const permissionLevels = result.join('').replace(/,/g, '');
                console.log(permissionLevels, 'permissionLevels0-=0-=');

                if (password !== confirmPassword) {
                    this.$message({
                        message: '两次输入的密码不一致，请重新输入！',
                        type: 'error'
                    });
                    return;
                }

                let url='http://127.0.0.1:8001/adu?nu='+username+'&np='+password+'&perm='+permissionLevels+'&u=admin'+'&p=admin'
                fetch(url)
                    .then(response => response.json())
                    .then(data => {
                        if(data.code == 4) {
                            this.$message({
                                message: '请输入管理员密码息',
                                type: 'error'
                            });
                        } else if (data.code == 3) {
                            this.$message({
                                message: '密码输入格式有误，密码需要有大写字母、小写字母、特殊符号和数字，不能小于8位',
                                type: 'error'
                            });
                        } else if (data.code == 1) {
                            this.$message({
                                message: '用户已存在',
                                type: 'error'
                            });
                        } else if (data.code == 2) {
                            this.$message({
                                message: '数据库错误',
                                type: 'error'
                            });
                        } else if (data.code == 5) {
                            this.$message({
                                message: '管理员用户名或密码错误',
                                type: 'error'
                            });
                        } else if (data.code == 0) {
                            this.$message({
                                message: '注册成功，请登录',
                                type: 'success'
                            });
                            location.reload()
                            document.getElementById('loginDiv').style.display = 'none'
                        } else {
                            alert('未知错误')
                        }
                    })
                // .catch(error => {
                //     alert('注册请求出错，请稍后再试');
                // });
            }
        }
    })
</script>
</body>
</html>